package com.tinckay.service.impl;

import com.tinckay.service.RedisService;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.security.Key;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Jean
 * @Desc:
 * @Date: 2018/11/5 19:32
 */
@Service
public class RedisServiceImpl implements RedisService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void setValue(String key, Object value, long timeout, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
    }

    @Override
    public Object getValue(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    @Override
    public void removeKey(String key) {
        redisTemplate.delete(key);
    }

    @Override
    public void put(String hashKey, Object key, Object value) {
        redisTemplate.opsForHash().put(hashKey, key, value);
    }

    @Override
    public void putAll(String hashKey, Map<Object, Object> map) {
        redisTemplate.opsForHash().putAll(hashKey, map);
    }

    @Override
    public Map<String, Object> entries(Object key) {
        return redisTemplate.opsForHash().entries(key);
    }


}
